﻿using UnityEngine;
using System.Collections;

public class MessageDemo : MonoBehaviour {

    public GameObject target;
    private bool doTest = false;

    public int messageCount = 0;

	// Use this for initialization
	void Start () {
        doTest = true;
	}
	
	// Update is called once per frame
	void Update () {

        if (doTest && target != null)
        {
            doTest = false;
            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();

            timer.Start();
            for (int i = 0; i < 1000; i++) target.SendMessage("GetMessage");
            timer.Stop();
            print("SendMessage: " + timer.Elapsed.ToString());

            timer.Reset();

            timer.Start();
            for (int i = 0; i < 1000; i++) target.GetComponent<MessageDemo>().GetMessage(); ;
            timer.Stop();
            print("GetComponent: " + timer.Elapsed.ToString());

        }
	}

    void GetMessage()
    {
        messageCount += 1;
    }
}
